$(document).ready(function() {
    //data table
    $('#infoTable').dataTable({
        "bJQueryUI": true,
        "bPaginate": true,
        "sPaginationType": "full_numbers",
        "bFilter": true,
        "bSort": true,
        "iDisplayLength": 5,
        "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]]
    });

    $(document).ready(function() {
        $('#delusercou').click(function(){
            var amt = $('input[name="course_id[]"]:checked').length;
            if(amt == 0){
                alert("Please select at least one course to delete");
            }else{
                var response = confirm('Delete all marked ? ('+amt+' course(s) marked)');
                if(response){
                    var allVals = [];
                    $('input[name="course_id[]"]:checked').each(function() {
                        $(this).parent().parent().remove();
                        allVals.push($(this).val());
                    });
                    var urls = $("#ucouurl").val();
                    $.post(urls,{
                        'course_id':allVals
                    },function(data){
                        alert("Delete Successfully");
                    })
                }
            }
        });
    });



    $("#selectCouConfirm").click(function(){
        var amt = $('input[name="course_id[]"]:checked').length;
        if(amt == 0){
            alert("Please select at least one course");
            return false;
        }
    });


    function check(){
        var textarea = $("#courseDesc").val();
        if(textarea == ""){
            $("#result").text("There are some blank fields");
            $("#courseDesc").css("border-color", "red");
            return false;
        }else{
            var urls = $("#couurl1").val();
            $.post(urls, {
                'courseDesc':courseDesc
            }, function(data){
                var values = data.split("|");
                $("#result").text(values[0]);
                if(values[1] == "Yes" ){
                    setTimeout(function(){
                        document.location.href='../selection_course/'
                    },2000);
                }else{
                    $("#courseDesc").css("border-color", "red");
                }
            });
            return true;
        }
    }



});